# Build script for perl and perl-cross.
# Perl-cross URL: http://arsv.github.io/perl-cross/
#
# Copyright (c) 2014-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version=5.32.1
cross_ver=1.3.5

cd -- "$TMPDIR"
rm -rf perl-${version} perl-cross-${cross_ver}
unpack "${worktree}/sources/perl-${version}.tar.gz" \
       "${worktree}/sources/perl-cross-${cross_ver}.tar.gz"

# Copy perl-cross over Perl distribution
cp -f -r perl-cross-${cross_ver}/* perl-${version}/

# Build instructions
cd perl-${version}

./configure \
 --prefix=/tools \
 --target=$target \
 --all-static \
 -Dusethreads \
 -Dprivlib=/tools/lib${libSuffix}/perl5 \
 -Dsitelib=/tools/lib${libSuffix}/perl5/site_perl \
 -Dldflags="$BTLDFLAGS -static"

make -j1

mkdir -p -- "${rootdir}/tools/bin" "${rootdir}/tools/lib${libSuffix}/perl5"
cp -f perl cpan/podlators/scripts/pod2man "${rootdir}/tools/bin"
cp -R lib/* "${rootdir}/tools/lib${libSuffix}/perl5"

cleanup()
{
    cd -- "$TMPDIR" && rm -rf perl-${version} perl-cross-${cross_ver}
}

